<?php
include("../common.inc.php");
InitGP(array("page","action","uid","delids")); //初始化變量全局返回
include("function_common.php");
//初始化對象
include(INC_PATH."/member.class.php");
$m=new memberclass();


if(empty($action)){
	InitGP(array("uid","uname","email")); //初始化變量全局返回
	if(!empty($uid))$wherestr[]="uid = '{$uid}'";
	if(!empty($email))$wherestr[]="email like '%{$email}%'";
	if(!empty($uname))$wherestr[]="uname like '%{$uname}%'";
	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//條件匯總
	
	//獲取當前頁碼
	$total=$m->getcount($wheresql); 							  //總信息數
	$pagesize=15;												  //一頁顯示信息數
	$page = isset($page) ? max(1, intval($page)) : 1;             //處理頁碼變量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$m->getdata("$offset,$pagesize",$wheresql); //獲取團購數據
	
	//包含後台模板文件
	include("tpl/user_list.htm");
}elseif ($action=="update") {
	//更新狀態禁用或者啟用
	
	InitGP(array("uid")); //初始化變量全局返回
	//$state=$m->state($uid)?0:1;
	//$m->state($uid,$state);
	//showmsg("設置狀態成功!","user_list.php");//成功
}elseif ($action=="edit") {
	InitGP(array("uid","uname","email","pwd","qq","tel","zip","address","score","oldmoney","money","Submit")); //初始化變量全局返回
	if(!empty($Submit)){
		//處理提交動作
		if(isset($uid) && isset($uname) && isset($email)){
			//處理數據
			$uid=GetNum($uid);
			$uname=Char_cv($uname);
			$address=Char_cv($address);
			
			if ($oldmoney!=$money) {
				$num=$money-$oldmoney;
				$note="管理員編輯用戶";
				$m->moneyedit($uname,$num,$note);
			}
			//執行回覆
			$editarray=array(
				"qq"=>$qq,
				"tel"=>$tel,
				"zip"=>$zip,
				"address"=>$address,
				"score"=>$score
			);
			
			$info=$m->edit($uname,$email,$oldpassword,$pwd,$editarray);
			
			//$info=$m->replay($uid,$reply);
			if($info=="OK"){
				showmsg("編輯成功!","user_list.php");//成功
			}else showmsg($info,"-1");//出錯！
		}else showmsg("缺少參數11","-1");//出錯！

	
	
	
	}else {
	
	//編輯信息表單
	$dataedit=$m->getdata(1,"uid={$uid}");
	$value=$dataedit[0];//獲取第一條記錄
	//包含後台模板文件
	include("tpl/user_list.htm");	
	}
}elseif ($action=="del" && !empty($uid)){
	//執行刪除操作
	$uid=GetNum($uid);
	$info=$m->del($uid);
	if($info=="OK")showmsg("刪除用戶成功！","user_list.php");
	else showmsg($info,"user_list.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("沒有選擇任何對象！","user_list.php");exit;}//空選擇
	//執行刪除多個操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$m->del($id);
	}
	if($info=="OK")showmsg("刪除用戶成功！","user_list.php");
	else showmsg($info,"user_list.php");
}elseif($action=="downxls"){

	//獲取當前頁碼
	$total=$m->getcount(); 							  //總信息數
	$dataarray=$m->getdata(); //獲取數據
	
	$keynames=array(
	"uid"=>"用戶ID",
	"uname"=>"用戶名",
	"email"=>"用戶Email",
	"tel"=>"手機號",
	"score"=>"積分",
	"money"=>"帳戶餘額",
	"groupcount"=>"參團次數"
	);
	
	down_xls($dataarray, $keynames,'dataxls_'.$total);
}

?>

